print("202509260954")
if not game:IsLoaded() then
    game.Loaded:Wait()
end

local marketplace_service = game:GetService("MarketplaceService")
local replicated_storage = game:GetService("ReplicatedStorage")
local local_player = game:GetService("Players").LocalPlayer
local run_service = game:GetService("RunService")
local workspace = game:GetService("Workspace")
local stats = game:GetService("Stats")

-- replicated_storage:WaitForChild("Remotes"):WaitForChild("HarvestPlant")

-- replicated_storage:WaitForChild("Remotes"):WaitForChild("RequestTrade")

-- replicated_storage:WaitForChild("Remotes"):WaitForChild("BuyItemFromShop")
-- 日志函数优化
local log = function(s, metadata) -- 日志
    -- log(s, metadata): 记录到 log.txt；仅交易相关类型才上传到 Loki
    local logMessage = string.format("[%s] %s", os.date("%Y-%m-%d %H:%M:%S"), tostring(s))

    -- 记录到本地文件
    local success, err = pcall(function()
        appendfile("log.txt", logMessage .. "\n")
    end)
    if not success then
        writefile("log.txt", logMessage .. "\n")
    end

end
-- 获取ReplicatedStorage中的所有子对象
local replicated_children = replicated_storage:GetChildren()

-- 打印所有子对象的名称和类型
for _, child in ipairs(replicated_children) do
    print("名称:", child.Name, "类型:", child.ClassName)
    log("名称: " .. child.Name .. " 类型: " .. child.ClassName)
    -- 如果是文件夹或模型，递归打印其子对象
    if child:IsA("Folder") or child:IsA("Model") then
        print("  子对象:")
        log("  子对象:: " )
        for _, subchild in ipairs(child:GetChildren()) do
            print("    -", subchild.Name, "类型:", subchild.ClassName)
            log("    - " .. subchild.Name .. " 类型: " .. subchild.ClassName)
        end
    end
end
-- 查找RequestTrade及其所有子对象
local function listDescendants(parent, path)
    for _, child in ipairs(parent:GetChildren()) do
        local currentPath = path .. "." .. child.Name
        print(currentPath .. " (" .. child.ClassName .. ")")
        log(currentPath .. " (" .. child.ClassName .. ")")
        -- 递归列出所有后代对象
        listDescendants(child, currentPath)
    end
end

-- 查找RequestTrade
-- if replicated_storage:FindFirstChild("RequestTrade") then
--     print("=== RequestTrade 枚举开始 ===")
--     listDescendants(replicated_storage.RequestTrade, "RequestTrade")
--     print("=== RequestTrade 枚举结束 ===")
-- else
--     warn("ReplicatedStorage 下未找到 RequestTrade")
-- end

-- local Farms = workspace.Farm
-- local function GetFarms()
-- 	return Farms:GetChildren()
-- end
-- local function GetFarmOwner(Farm: Folder): string
-- 	local Important = Farm.Important
-- 	local Data = Important.Data
-- 	local Owner = Data.Owner

-- 	return Owner.Value
-- end
-- local function GetFarm(PlayerName: string): Folder?
-- 	local Farms = GetFarms()
-- 	for _, Farm in next, Farms do
-- 		local Owner = GetFarmOwner(Farm)
-- 		if Owner == PlayerName then
-- 			return Farm
-- 		end
-- 	end
--     return
-- end
-- local function GetArea(Base: BasePart)
-- 	local Center = Base:GetPivot()
-- 	local Size = Base.Size

-- 	--// Bottom left
-- 	local X1 = math.ceil(Center.X - (Size.X/2))
-- 	local Z1 = math.ceil(Center.Z - (Size.Z/2))

-- 	--// Top right
-- 	local X2 = math.floor(Center.X + (Size.X/2))
-- 	local Z2 = math.floor(Center.Z + (Size.Z/2))

-- 	return X1, Z1, X2, Z2
-- end
-- local MyFarm = GetFarm(local_player.Name)
-- local MyImportant = MyFarm.Important
-- local PlantLocations = MyImportant.Plant_Locations
-- local PlantsPhysical = MyImportant.Plants_Physical
-- local info = marketplace_service:GetProductInfo(game.PlaceId)

-- local Dirt = PlantLocations:FindFirstChildOfClass("Part")
-- local X1, Z1, X2, Z2 = GetArea(Dirt)

-- local function GetRandomFarmPoint(): Vector3
--     local FarmLands = PlantLocations:GetChildren()
--     local FarmLand = FarmLands[math.random(1, #FarmLands)]

--     local X1, Z1, X2, Z2 = GetArea(FarmLand)
--     local X = math.random(X1, X2)
--     local Z = math.random(Z1, Z2)

--     return Vector3.new(X, 4, Z)
-- end

-- local IsSelling = false
-- local AutoWalkAllowRandom = true
-- local AutoWalkMaxWait = 10

-- local function GetHarvestablePlants(IgnoreDistance: boolean?)
--     local Plants = {}
--     -- CollectHarvestable(PlantsPhysical, Plants, IgnoreDistance)
--     return Plants
-- end
-- local function AutoWalkLoop()
-- 	if IsSelling then return end

--     local Character = local_player.Character
--     local Humanoid = Character.Humanoid

--     local Plants = GetHarvestablePlants(true)
-- 	local RandomAllowed = AutoWalkAllowRandom
-- 	local DoRandom = #Plants == 0 or math.random(1, 3) == 2

--     --// Random point
--     if RandomAllowed and DoRandom then
--         local Position = GetRandomFarmPoint()
--         Humanoid:MoveTo(Position)
--         return
--     end
   
--     --// Move to each plant
--     for _, Plant in next, Plants do
--         local Position = Plant:GetPivot().Position
--         Humanoid:MoveTo(Position)
--     end
-- end

-- local function jump()
--     local keys = { 0x20, 0x20, 0x20, 0x20, 0x41, 0x44, 0x53, 0x57 }
--     local randomKey = keys[math.random(1, #keys)]
--     pcall(function()
--         keypress(randomKey)
--         task.wait(0.2)
--         keyrelease(randomKey)
--     end)
-- end

-- task.spawn(function()
--     -- jump(): 每 60 秒随机按键一次，保持角色活跃。
--     while task.wait(60) do
--         jump()
--         AutoWalkLoop()
--     end
-- end)
